import { GTable, GFormSchema, SchemaFieldComponents } from 'geminis-react';
import { PurchaseProductBatchSelect } from '@/pages/purchase/components/PurchaseProductBatchSelect';

SchemaFieldComponents['PurchaseProductBatchSelect'] = PurchaseProductBatchSelect;

export const Failed = (props: any) => {
  const schema = {
    table: {
      schema: {
        data: {
          url: '/api/warehouse/purchase/checkFailed',
          filter: {
            filters: [
              {
                field: 'purchase.id',
                compareType: '=',
                value: props.orderId,
              },
            ],
          },
        },
      },
      schemaPath: '/warehouse-pc/schemas/purchase/check/failed-table.json',
    },
    add: {
      form: {
        schema: {
          data: {
            url: '/api/warehouse/purchase/checkFailed',
            includes: ['productBatch'],
          },
          fields: {
            properties: {
              'productBatch.id': {
                'x-component-props': { orderId: props.orderId },
              },
            },
          },
        },
        schemaPath: '/warehouse-pc/schemas/purchase/check/failed-form.json',
        onSubmitting: (value: any) => {
          value.purchase = { id: props.orderId };
        },
      },
    },
  };

  return <GTable schema={schema} />;
};
